/**
  * Author: Mei
  * Date: 2020-10-16 20:52
  * Description: 
  *
  */
#include <iostream>

using namespace std;

class Calculator {
public:
    double a, b;

    Calculator(double a, double b) : a(a), b(b) {}

    virtual double result() const = 0;
};
class Add : public Calculator {
public:
    Add(double a, double b) : Calculator(a, b) {}

    double result() const {
        return a + b;
    }
};

class sub : public Calculator {
public:
    sub(int a, int b) : Calculator(a, b) {}

    double result() const {
        return a - b;
    }
};

class multi : public Calculator {
public:
    multi(int a, int b) : Calculator(a, b) {}

    double result() const {
        return a * b;
    }
};

class divi : public Calculator {
public:
    divi(int a, int b) : Calculator(a, b) {}

    double result() const {
        return a / b;
    }
};

//工厂
class Factory { //声明的工厂
public:
    static Calculator *create(char sign, int a, int b);
};

Calculator *Factory::create(char sign, int a, int b) {
    Calculator *p;
    switch (sign) {
        case '+':
            p = new Add(a, b);
            break;
        case '-':
            p = new sub(a, b);
            break;
        case '*':
            p = new multi(a, b);
            break;
        case '/':
            p = new divi(a, b);
            break;
        default:
            p = new Add(a, b);
            break;
    }
    return p;
}

int main() {
    Calculator *p = Factory::create('/', 2, 3);
    cout << p->result() << endl;

    return 0;
}